
<template>
  <div>
    <SearchForm
        @search="onSearch"
        @reset="onReset"
        :search-list="searchList" :search-params="searchParams">
    </SearchForm>

    <div class="table-layout">
      <el-card shadow="never">
<!--        <div class="table-handle">-->
<!--          <el-button type="primary" size="mini" icon="el-icon-plus" @click="onAdd">新增</el-button>-->
<!--        </div>-->
        <div class="table-box">
          <el-table
              size="large"
              stripe
              border
              v-loading="loading"
              max-height="500px"
              :data="tableData"
              element-loading-spinner="el-icon-loading"
              element-loading-background="rgba(255, 255, 255, 0.8)"
              @selection-change="onSelect"
          >
            <el-table-column show-overflow-tooltip align="center" v-for="item in columns" :key="item.prop" :prop="item.prop" :label="item.label">
              <template slot-scope="scope">
                <template v-if="item.type === 'select'">
                  <el-tag :type="item.tagType" v-if="item.isTag">{{ item.mapping[scope.row[item.prop]] }}</el-tag>
                  <span v-else>{{ item.mapping[scope.row[item.prop]] }}</span>
                </template>
                <span v-else>{{ scope.row[item.prop] }}</span>
              </template>
            </el-table-column>
            <el-table-column label="操作" fixed="right" width="150px">
              <template slot-scope="scope">
                <el-button type="text" @click="onView(scope.row)">查看投递简历</el-button>
                <el-button type="text" style="color: #F82222" @click="onDelete(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="page-box">
          <el-pagination
              background
              :current-page="pageNo"
              :page-sizes="pageSizes"
              :page-size="pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="totalSize"
              @size-change="changePageSize"
              @current-change="changePageNo"
          />
        </div>
      </el-card>
    </div>
    <Add ref="addFormRef" @get-page="initData" />
  </div>
</template>
<script>

import crud from "@/mixins/crud";
import { http } from "@/api";
import Add from "./add";
export default {
  name: "index",
  components: {
    Add
  },
  mixins: [crud],
  data() {
    return {
      request: http.post,
      searchList: [
        {
          label: '发布类别',
          prop: 'category',
          name: 'select',
          clearable: true,
          options: [
          ]
        },

        {
          label: '职位类别',
          prop: 'post_category_id',
          name: 'selectTree',
          clearable: true,
          checkStrictly: false,
          nodeKey: 'id',
          props: {
            label: 'name',
            children: 'children'
          },
          options: [
          ]
        },
        {
          label: '公司',
          prop: 'user_id',
          name: 'select',
          clearable: true,
          options: [
          ]
        },
        {
          label: '名称',
          prop: 'name',
          name: 'input',
          clearable: true
        },
      ],
      searchParams: {
        name: '',
        category: '',
        post_category_id: '',
      },
      columns: [
        { prop: 'category', label: '发布类别' },
        { prop: 'post_category', label: '职位类型' },
        { prop: 'name', label: '职位名称' },
        { prop: 'count', label: '投递人数' },
        { prop: 'amount', label: '薪资' },
        { prop: 'welfare', label: '福利待遇' },
        { prop: 'desc', label: '职位描述' },
        { prop: 'company_name', label: '公司' },
        { prop: 'address', label: '上班地址' },
        { prop: 'nickname', label: '联系人' },
        { prop: 'phone', label: '联系人电话' },
        { prop: 'sort', label: '排序' },
        { prop: 'create_time', label: '创建时间' },
      ],
      tableData: [

      ]
    }
  },
  created() {
    http.category.list().then(res => {
      this.searchList[0].options = res.data.map(item => {
        return {
          label: item.name,
          value: item.name
        }
      });
    });
    http.postCategory.list({
      pid: 0
    }).then(res => {
      this.searchList[1].options = res.data;
    });
    http.user.list({
      role: 2
    }).then(res => {
      this.searchList[2].options = res.data.map(item => {
        return {
          label: item.company_name,
          value: item.id
        }
      });
    });
  },
  methods: {
    formatTableData(data) {
      return data.forEach(item => {
        if (item.user) {
          item.nickname = item.user.nickname;
          item.phone = item.user.phone;
          item.company_name = item.user.company_name;
        }
        item.count = item.postJoinList.length;
      });
    },
    onView(row) {
      this.$router.push({
        name: 'postJoin',
        query: {
          id: row.id
        }
      })
      }
  }
}
</script>

<style scoped lang="scss">

</style>
